﻿#include "YinDevilNode.h"
#include "../MapObject.h"
#include "../../../Shared/Data/Stat.h"
#include "../../Settings.h"
#include "../../../Shared/ServerPackets.h"
#include "../DelayedAction.h"

using namespace Server::MirDatabase;
namespace S = ServerPackets;

namespace Server::MirObjects::Monsters
{

    bool YinDevilNode::getCanMove() const
    {
        return false;
    }

    YinDevilNode::YinDevilNode(MonsterInfo *info) : MonsterObject(info)
    {
    }

    void YinDevilNode::Turn(MirDirection dir)
    {
    }

    bool YinDevilNode::Walk(MirDirection dir)
    {
        return false;
    }

    void YinDevilNode::ProcessRoam()
    {
    }

    void YinDevilNode::CompleteAttack(std::vector<std::any> &data)
    {
        std::vector<MapObject*> targets = FindAllTargets(7, getCurrentLocation());
        if (targets.empty())
        {
            return;
        }

        for (int i = 0; i < targets.size(); i++)
        {
            setTarget(targets[i]);
            if (getTarget() == nullptr || !getTarget()->IsFriendlyTarget(this) || getTarget()->getCurrentMap() != getCurrentMap() || getTarget()->Node == nullptr)
            {
                continue;
            }

            BuffType type = Info->AI == 41 ? BuffType::BlessedArmour : BuffType::UltimateEnhancer;

            auto stats = new Stats();
            stats.[type == BuffType::BlessedArmour ? Stat::MaxAC : Stat::MaxDC] = getTarget()->getLevel() / 7 + 4;

            getTarget()->AddBuff(type, this, Settings::Second * 5, stats);
            getTarget()->OperateTime = 0;

//C# TO C++ CONVERTER TODO TASK: A 'delete stats' statement was not added since stats was passed to a method or constructor. Handle memory management manually.
        }

    }

    void YinDevilNode::ProcessTarget()
    {
        if (!getCanAttack())
        {
            return;
        }
        if (!FindFriendsNearby(7))
        {
            return;
        }

        ShockTime = 0;

        S::ObjectAttack *tempVar = new S::ObjectAttack();
        tempVar->ObjectID = ObjectID;
        tempVar->Direction = getDirection();
        tempVar->Location = getCurrentLocation();
        Broadcast(tempVar);
        DelayedAction tempVar2(DelayedType::Damage, getEnvir()->getTime() + 500);
        ActionList.push_back(&tempVar2);
        ActionTime = getEnvir()->getTime() + 300;
        AttackTime = getEnvir()->getTime() + AttackSpeed;

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was passed to a method or constructor. Handle memory management manually.
    }
}
